package com.team20.map_demo.service;

import com.github.pagehelper.PageHelper;
import com.team20.map_demo.domain.Approval;
import com.team20.map_demo.domain.ApprovalExample;
import com.team20.map_demo.mapper.ApprovalMapper;
import io.micrometer.core.instrument.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ApprovalServiceImpl implements ApprovalService {
    @Autowired
    private ApprovalMapper approvalMapper;

    @Override
    public int saveAppr(Approval approval) {
        if(StringUtils.isNotBlank(approval.getId()))
            return approvalMapper.updateByPrimaryKey(approval);
        else
            return approvalMapper.insert(approval);
    }

    /*@Override
    public int insert(Approval approval) {
        return approvalMapper.insert(approval);
    }*/

    @Override
    public Approval selectByPrimaryKey(String id) {
        return approvalMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Approval> listAppr(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        return approvalMapper.selectByExample(new ApprovalExample());
    }

    @Override
    public int deleteById(String id) {
        return approvalMapper.deleteByPrimaryKey(id);
    }
}
